Những câu hỏi liên quan
Hiếu Phí Lê
Xem chi tiết
Hiếu Phí Lê
Xem chi tiết
Nguyên Hưng Trần
23 tháng 7 2021 lúc 19:52

Uses crt;

var i,n:longint;

     S,A:real;

begin

clrscr;

Readln(A);

S:=0;n:=0;

while S<=A do

  Begin

  S:=0; 

  inc(n);

  for i:= 1 to n do S:=S+1/i;

  end;

Writeln(n);

readln;

end.

Bình luận (0)
pthaokuche
Xem chi tiết
Nguyễn Lê Phước Thịnh
13 tháng 11 2021 lúc 0:16

uses crt;

var a,b:longint;

begin

clrscr;

readln(a,b);

writeln(a*b);

readln;

end.

Bình luận (0)
Hiếu Phí Lê
Xem chi tiết
Hoàng Duy
Xem chi tiết
Thanh Bình
Xem chi tiết
Nguyễn Hoàng Duy
27 tháng 6 2023 lúc 16:57

def exchange(n, memo):
    if n in memo:
        return memo[n]
    if n == 0:
        return 0
    max_exchange = max(n, exchange(n // 2, memo) + exchange(n // 3, memo) + exchange(n // 4, memo))
    memo[n] = max_exchange
    return max_exchange

while True:
    try:
        n = int(input())
        memo = {}
        print(exchange(n, memo))
    except:
        break
    

Bình luận (0)
Thanh Bình
Xem chi tiết
Gia Huy
27 tháng 6 2023 lúc 17:40

```python
n = int(input())
p = list(map(int, input().split()))

pos = [0] * n
for i in range(n):
pos[p[i]-1] = i

count = 0
for i in range(n):
if pos[i] != i:
j = pos[i]
pos[i], pos[j] = pos[j], pos[i]
count += 1

print(count)
```

Bình luận (0)
Thanh Bình
27 tháng 6 2023 lúc 16:46

Pascal, c++ hay python gì cũng được

Bình luận (0)
Thanh Bình
Xem chi tiết
Nguyễn Hoàng Duy
27 tháng 6 2023 lúc 17:20
#include<bits/stdc++.h>using namespace std;string s;long long c[1000001],w[1000001];int main() {getline(cin,s);long long n = s.size();if(s[n-1] == 'a' || s[n-1] == 'e' || s[n-1] == 'i' || s[n-1] == 'o' || s[n-1] == 'u') c[n-1] = 0;else c[n-1] = 1;for(int i = n-2;i >= 0;i--) {if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u') {c[i] = c[i+1];}else {c[i] = c[i+1]+1;}}if(s[n-1] == 'a' || s[n-1] == 'e' || s[n-1] == 'i' || s[n-1] == 'o' || s[n-1] == 'u') w[n-1] = 1;else w[n-1] = 0;for(int i = n - 2; i >= 0;i--) {if(s[i] != 'a'&s[i] != 'e'& s[i] != 'i' &s[i] != 'o'&s[i] != 'u') {w[i] = w[i+1];}else w[i] = w[i+1]+1;}long long dem = 0;for(int i = 0;i < s.size();i++) {if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u') {dem = dem + c[i];}else {dem = dem + w[i];}}cout << dem;return 0;}    
Bình luận (2)
Tiếng anh123456
Xem chi tiết
Nguyễn Hoàng Duy
12 tháng 8 2023 lúc 14:49

Tham Khảo:

#include <bits/stdc++.h>

using namespace std;

bool v(int y, int x) {

return 1 <= y && y <= 8 && 1 <= x && x <= 8;

}

int m(int y, int x, int ty, int tx) {

if (!v(y, x) || !v(ty, tx)) {

return -1;

}

deque<pair<int, pair<int, int>>> q;

q.push_back({y, {x, 0}});

bool vis[9][9] = {false};

vis[y][x] = true;

int dx[] = {-2, -2, 2, 2};

int dy[] = {-2, 2, -2, 2};

while (!q.empty()) {

int cy = q.front().first;

int cx = q.front().second.first;

int s = q.front().second.second;

q.pop_front();

if (cy == ty && cx == tx) {

return s;

}

for (int i = 0; i < 4; ++i) {

int ny = cy + dy[i];

int nx = cx + dx[i];

if (v(ny, nx) && !vis[ny][nx]) {

q.push_back({ny, {nx, s + 1}});

vis[ny][nx] = true;

        }

    }

}

return -1;

}

int main() {

int y, x, ty, tx;

cin >> y >> x >> ty >> tx;

cout << m(y, x, ty, tx) << endl;

return 0;

}

Bình luận (0)